﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using Meqs.Logic.Interface;
using System.Collections.Generic;
public partial class TeacherEval_School_RuleSettings_SettingEvalDefault : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Repeater1.DataSource = GetEvalList();
            Repeater1.DataBind();
        }
    }


    /// <summary>
    /// 获取当前学年学期的带有课程名的学分记录
    /// </summary>
    /// <returns></returns>
    private IList<TeacherEvalHistory> GetEvalList()
    {
        SchoolInfo si = SchoolCommon.Sch_SchoolInfo;
        int schoolYear = si.SchoolYear;
        int term = si.SchoolTerm;
        string schoolMark = si.SchoolMark;

        ITeacherEvalHistoryLogic logic = Container<ITeacherEvalHistoryLogic>.Instance;
        //判断当前学年学期是否有数据，没有则添加
        if (!ValidateIsNewTerm())
        {
            //TODO:
            // logic.CreateNewTermHistory(schoolYear,term);
        }

        Hashtable ht = new Hashtable();
        ht.Add("SchoolYear",schoolYear);
        ht.Add("Term", term);
        ht.Add("SchoolMark", si.SchoolMark);
        ht.Add("Site", TeacherEvalHistory.SystemSiteName);
        IList<TeacherEvalHistory> list = logic.FindAll(ht);
        return list;
    }

    /// <summary>
    /// 验证当前是否是新学年学期
    /// </summary>
    /// <returns></returns>
    private bool ValidateIsNewTerm()
    {
        int schoolYear = SchoolCommon.Sch_SchoolInfo.SchoolYear;
        int term = SchoolCommon.Sch_SchoolInfo.SchoolTerm;

        IStuCauseEvalHistoryLogic logic = Container<IStuCauseEvalHistoryLogic>.Instance;
        Hashtable table = new Hashtable();
        table.Add("SchoolMark", Common.GetConstSchoolMark());
        table.Add("SchoolYear", SchoolCommon.Sch_SchoolInfo.SchoolYear);
        table.Add("Term", SchoolCommon.Sch_SchoolInfo.SchoolTerm);

        List<StuCauseEvalHistory> list = (List<StuCauseEvalHistory>)logic.FindAll(table);

        if (list.Count > 0)
            return true;
        else
            return false;

    }

    [System.Web.Services.WebMethod]
    public static int SaveSure(int [] ids)
    {
        ITeacherEvalHistoryLogic logic = Container<ITeacherEvalHistoryLogic>.Instance;
        foreach (int i in ids)
        {
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", Common.GetConstSchoolMark());
            ht.Add("RID",i);
            ht.Add("Status", 1);
            logic.UpdateStatus(ht);
        }
        
        return 1;
    }

    protected void btnBind_Click1(object sender, EventArgs e)
    {
        Repeater1.DataSource = GetEvalList();
        Repeater1.DataBind();
    }
}
